Structs with no fields or all-ZST fields are ZSTs#2262
Conversation
ba89b4f to
51e8478
Compare
51e8478 to
9c34b1e
Compare
6a2c83a to
5011dcd
Compare
|
cc @RalfJung @rust-lang/opsem |
| For [structs] with no fields, or where all fields are [zero-sized], it is further guaranteed that the structs are themselves [zero-sized]. | ||
|
|
||
| r[layout.repr.rust.enum-struct-like-zst] | ||
| For [enums] (without a primitive representation specified) with a single struct-like variant with no fields or where all fields are [zero-sized], the enum itself is [zero-sized]. |
There was a problem hiding this comment.
Seems bizarre to guarantee this for struct-like variants but not unit-like variants or tuple-like variants.
|
That seems reasonable to me (specifically for |
|
We talked about this in the lang call today. Let's propose to do this with the correction that, for enums, we mean those @rfcbot fcp merge lang |
|
@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
@rfcbot concern check-randomize-layout |
|
This seems stronger than what we guarantee for non-ZST structs, which require I don't see a reason not to make this guarantee, and it seems like a useful one, so let's do it. @rfcbot reviewed |
|
Should we also guarantee that zero-variant
Yes, I believe it is. IIUC the current implementation of reasoningWhen the
I opened a PR rust-lang/rust#157905 to update the comments in some of the places where
~~Nominating for possibly resolving the Footnotes
|
|
Error: Label I-lang-nominated can only be set by Rust team members Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip. |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
This wording doesn't seem super clear on whether or not repr(C) enums are excluded (which they should be, because they are implicitly repr(C, Int), where Int is a target-specific integer type, but that isn't "specified" in the repr attribute). |
67b1047 to
fa61cbd
Compare
Done, fa61cbd @rustbot ready |
In the glossary, the new entries start with On the type layout page, the entries are under the |
edec521 to
034e3cf
Compare
| For [structs] with no fields or where all fields are [zero sized], it is further guaranteed that the structs are themselves [zero sized]. | ||
|
|
||
| r[layout.repr.rust.enum-struct-like-zst] | ||
| For [enums] (without a primitive representation specified) with a single field-struct-like variant, a single unit-struct-like variant, or a single tuple-struct-like variant and where the struct-like thing has no fields or where all of the fields are [zero sized], the enums themselves are [zero sized]. |
There was a problem hiding this comment.
Let's add links to cross-reference each of these, here and in the glossary.
| For [structs] with no fields or where all fields are [zero sized], it is further guaranteed that the structs are themselves [zero sized]. | ||
|
|
||
| r[layout.repr.rust.enum-struct-like-zst] | ||
| For [enums] (without a primitive representation specified) with a single field-struct-like variant, a single unit-struct-like variant, or a single tuple-struct-like variant and where the struct-like thing has no fields or where all of the fields are [zero sized], the enums themselves are [zero sized]. |
There was a problem hiding this comment.
Let's add links to cross-reference each of these, here and in the glossary.
New rule `layout.repr.rust.struct-zst` adds the guarantee that `repr(Rust)` structs with no fields or all ZST fields are ZSTs. New rule `layout.repr.rust.enum-struct-like-zst` adds the guarantee that `repr(Rust)` enums with a single struct-like variant with no fields or all ZST fields are ZSTs. The glossary entry for ZSTs is expanded with references to these guarantees and examples.
034e3cf to
08c1565
Compare
|
Thanks @DanielEScherzer. |
Guarantee that structs with Rust representation and with no fields, or where all fields are ZSTs, are themselves ZSTs.
Guarantee that enums with Rust representation with a single struct-like variant with no fields, or where all fields are ZSTs, are themselves ZSTs.